package com.atguigu.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.List;
import java.util.Map;

/**
 * 获取CLOB字段图片
 * 
 * @author JackJin
 * @date 2020年3月14日 上午9:08:36
 */
public class ClobImg {
	public static void getClobImg(List<Map<String, Object>> list, String column) {
		InputStream i = null;
		ByteArrayOutputStream output = null;
		try {
			for (Map<String, Object> m : list) {
				if (m.get("fileImg") instanceof InputStream) {
					i = (InputStream) m.get(column);
					output = new ByteArrayOutputStream();
					byte[] buffer = new byte[2048];
					int n = 0;
					while (-1 != (n = i.read(buffer)))
						output.write(buffer, 0, n);
					String result = Base64.getEncoder().encodeToString(output.toByteArray());
					m.put("fileImg", result);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (output != null) {
					output.close();
				}
				if (i != null) {
					i.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
